const db = uniCloud.database()
module.exports = {
	_before: function() { // 通用预处理器

	},
	async getData(form) {
		let skip = 0
		if (form.skip === 0 || form.skip === 1) {
			skip = 0
		} else {
			skip = (form.skip - 1) * form.limit
		}

		let search = {}

		if (form.id) {
			search._id = form.id
		} else if (form.userId) {
			search.userId = form.userId
		} else if (form.status || form.status === 0) {
			search.status = form.status
		}
		
		
		return {
			data: await db.collection("self-order").where(search).skip(skip).limit(form.limit).orderBy('time','desc').get(),
			total: await db.collection("self-order").where(search).count(),
			code: 0,
			message: "成功"
		}
	},
	async orderStatus(from){
		await db.collection("self-order").doc(from.id).update({status: from.status})
		
		return {
			code: 0,
			message: "成功"
		}
	}
}